package cn.shenlong.portal.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.shenlong.portal.domain.Site;
import cn.shenlong.portal.service.SiteService;

@Controller
@RequestMapping("/site/admin")
public class SiteAController {
	
	@Autowired
	private SiteService siteService;
	

	/**
	 * 查看商家信息
	 * @param siteId 网站ID
	 * @param model
	 * @return
	 */
	@RequestMapping("/seedSite")
	public String seedSite(Long siteId,ModelMap model){
		if(siteId!=null && siteId>0){
			Site site = siteService.findByPK(siteId);
			model.put("siteId", siteId);
			model.put("site", site);
			return "/server/site/show";
		}else{
			model.addAttribute("errorMsg", "站点ID传递参数错误!");
			return "/common/error";
		}
	}
	
	/**
	 * 编辑站点信息
	 * @param siteId 网站ID
	 * @param model
	 * @return
	 */
	@RequestMapping("/editSite")
	public String editSite(Long siteId,ModelMap model){
		if(siteId!=null && siteId>0){
			Site site = siteService.findByPK(siteId);
			model.put("siteId", siteId);
			model.put("site", site);
			return "/server/site/edit";
		}else{
			model.addAttribute("errorMsg", "站点ID传递参数错误!");
			return "/common/error";
		}
	}	
	
    /**
     * 保存数据 
     * @param site 网站信息
     * @param model
     * @return
     */
	@RequestMapping("/updateSite")
	public String save(Site site,ModelMap model ){
		siteService.updateEntity(site);
		return "redirect:seedSite.html?siteId="+site.getSiteId();
	}
}
